//
//  GameOverLayer.m
//  SpeedTap
//
//  Created by Chi Ho Chiu on 17/8/11.
//  Copyright 2011 Individual. All rights reserved.
//

#import "GameOverLayer.h"


@implementation GameOverLayer
@synthesize delegate;

-(id) init
{
    if( (self = [super initWithColor:ccc4(0, 0, 0, 100)] ) )
    {
        CGSize winSize = [[CCDirector sharedDirector] winSize];
        
        CCLabelBMFont *font = [CCLabelBMFont labelWithString:@"Game Over" fntFile:@"Dakota_white_48.fnt"];
        font.position = ccp(winSize.width/2, winSize.height/2);
        
        [self addChild:font];
                
        CCLabelBMFont *retryFont = [CCLabelBMFont labelWithString:@"Retry" fntFile:@"Dakota_white_24.fnt"];
        CCMenuItem *retryItem = [CCMenuItemLabel itemWithLabel:retryFont target:self selector:@selector(onMenuItemClicked:)];
        [retryItem setTag:kGAME_OVER_TAG_RETRY];
        [retryItem setAnchorPoint:ccp(1,1)];
        
        CCLabelBMFont *exitFont = [CCLabelBMFont labelWithString:@"Back to Menu" fntFile:@"Dakota_white_24.fnt"];
        CCMenuItem *exitItem = [CCMenuItemLabel itemWithLabel:exitFont target:self selector:@selector(onMenuItemClicked:)];
        [exitItem setTag:kGAME_OVER_TAG_EXIT];
        [exitItem setAnchorPoint:ccp(1,1)];
        
        CCMenu *menu = [CCMenu menuWithItems:retryItem, exitItem, nil];
        [menu alignItemsVertically];

        int menuItemsHeight = [retryItem contentSize].height + [exitItem contentSize].height;
        [menu setPosition: ccp( winSize.width, menuItemsHeight)];
        
        [self addChild:menu];
        
    }
    
    return self;
}

-(void) dealloc 
{
    [delegate release];
    [super dealloc];
}

-(void) onMenuItemClicked:(CCMenuItem *)menuItem
{
    switch (menuItem.tag) {
        case kGAME_OVER_TAG_RETRY:
            [delegate onRetryItemClicked];
            break;
        case kGAME_OVER_TAG_EXIT:
            [delegate onExitItemClicked];
            break;
        default:
            
            break;
    }
}

@end
